<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" http-equiv="">
<meta contentType="application/x-www-form-urlencoded">
	<title>OCRTest</title>
	<!-- JQuery on line -->
	<script type="text/javascript" src="../../../plugin/js/jquery-3.1.1.min.js"></script>
	<!-- <script type="application/json" src="https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=RTjlSY5m2RMyIelAR96fbpyk&client_secret=Wa0V4PHfIbZBWVsSsRGAS0NFV2n9EGcf"></script> -->
	<!-- bootstrap main js -->
	<script type="text/javascript" src="../../../plugin/js/bootstrap.min.js"></script>
	<!-- fileinput main js -->
	<script type="text/javascript" src="../../../plugin/js/fileinput.min.js"></script>
	<!-- chn language js -->
	<script type="text/javascript" src="../../../plugin/js/zh.js"></script>
	<!-- bootstrap theme -->
	<link rel="stylesheet" type="text/css" href="../../../plugin/css/bootstrap.min.css">
	<!-- fileinput theme -->
	<link rel="stylesheet" type="text/css" href="../../../plugin/css/fileinput.min.css">
</head>
<body>
<button id="requestToken" class="btn btn-success">获取token</button>
<form enctype="multipart/form-data" id="ocr-form" action="/ocr" method="post">
	<div class="col-sm-4">
		<div class="form-group">
			select File<input type="file" name="file" id="file-1" class="file">
		</div>
	</div>
</form>


<div id="test"></div>


<script type="text/javascript">
//Interface Param
//Program Name：TText
//AppID:10281445
//API Key:RTjlSY5m2RMyIelAR96fbpyk
//Secret Key:Wa0V4PHfIbZBWVsSsRGAS0NFV2n9EGcf

//A.fileupload init
$("#file-1").fileinput({
    uploadUrl: 'localhost:8080/image/', //你必须在这里设置一个有效的URL，否则你会得到一个错误
    uploadAsync: true, //AJAX设置同步，异步的上传方式 （同步）
    allowedFileExtensions: ['jpg', 'png', 'gif'],//文件类型
    showUpload: true, //是否显示上传按钮
    //browseClass: "btn btn-primary", //按钮样式 
    showRemove : true, //显示移除按钮
    dropZoneEnabled: true,//是否显示拖拽区域
    overwriteInitial: false,
    maxFilesNum: 10,
    maxFileCount: 4, //表示允许同时上传的最大文件个数
    minFileCount: 0,	//最少文件
    validateInitialCount:true,//异步上传返回结果处理
});
//https://aip.baidubce.com/oauth/2.0/token
var requrl = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=RTjlSY5m2RMyIelAR96fbpyk&client_secret=Wa0V4PHfIbZBWVsSsRGAS0NFV2n9EGcf";
$('#requestToken').click(function(){
	// var request = createCORSRequest('GET', requrl);
	// $.ajax({
	// 	url: requrl,
	// 	type: 'get',
	// 	dataType: 'json',
	// 	async: true,
	// 	xhrFields: {
	// 		withCredentials: true
	// 	},
	// 	success: function(data){
	// 		alert("成功"+data);
	// 	},
	// 	error: function(data){
	// 		alert("错误" + data);
	// 	}
	// });
	// $.getJSON("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=RTjlSY5m2RMyIelAR96fbpyk&client_secret=Wa0V4PHfIbZBWVsSsRGAS0NFV2n9EGcf",{},function(json){ 
	// 	console.log(json);
	// }); 
	$.post(requrl,{},function(data){
    console.log(data);//这个data就是test_post.php返回的数据
});
});




// 5KEgsZHLj3X5JrqEBF9n4p8GZTYS5bVtozJXmptqbVW9h1Tsjbq





function createCORSRequest(method,url) {
    var xhr = new XMLHttpRequest();
    //withCredentials是XMLHttpRequest2中独有的，用于判断浏览器是否支持XMLHttpRequest2
    if('withCredentials' in xhr) {
        xhr.open(method,url,true);
    }else if(typeof XDomainRequest != 'undefined'){
        xhr = new XDomainRequest();
        xhr.open(method,url);
    }else {
        xhr = null;
    }
    return xhr;
}
</script>
</body>
</html>